package tgc.edu.demo.jkxt.controller;

import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import tgc.edu.demo.jkxt.custom.AjaxResult;
import tgc.edu.demo.jkxt.custom.JwtTokenUtils;
import tgc.edu.demo.jkxt.security.UserUtils;



@RestController
@CrossOrigin
public class MainController {
	@Autowired
	private UserUtils userUtils;
	
	@RequestMapping(value = "/loginSucc")
	public Object loginSucc() {
		String name = userUtils.getName();
		String username = userUtils.getUsername();
		String roles = userUtils.getRoles();
		String token = JwtTokenUtils.createToken(username, name, roles);
		token=JwtTokenUtils.TOKEN_PREFIX+token;  //加上token前缀
	    HashMap<String, Object> result=new HashMap<String, Object>();
	    result.put("token",token);
	    result.put("name", name);
	    result.put("roles", roles);
	    return new AjaxResult("登录成功", result);
	}
	
	@RequestMapping(value = "/loginFail")
	public Object loginFail() {
		return new AjaxResult(false,"用户名或密码错误，登录失败");
	}
	
	@RequestMapping(value = "/logoutSucc")
	public Object logoutSucc() {
		return new AjaxResult("注销成功！");
	}
	
}
